#include "snakefield.h"

SnakeField::SnakeField(QObject *parent) :
    QObject(parent)
{
    fieldSize.first = MIN_LINES;
    fieldSize.second = MIN_COLUMNS;

    createEmptyField();
}

void SnakeField::setFieldSize(quint32 lines, quint32 columns)
{
    if(lines < MIN_LINES)
        lines = MIN_LINES;
    else
        if(lines > MAX_LINES)
            lines = MAX_LINES;

    if(columns < MIN_COLUMNS)
        columns = MIN_COLUMNS;
    else
        if(columns > MAX_COLUMNS)
            columns = MAX_COLUMNS;

    fieldSize.first = lines;
    fieldSize.second = columns;

    createEmptyField();
}

Point SnakeField::getFieldSize()
{
    return fieldSize;
}

void SnakeField::createEmptyField()
{
    field.resize(fieldSize.first);
    Field::iterator i = field.begin();
    while(i != field.end())
    {
        i->resize(fieldSize.second);
        QVector<Cell >::iterator j = i->begin();
        while(j != i->end())
        {
            (*j) = CELL_EMPTY;
            j++;
        }
        i++;
    }
}

const Field & SnakeField::getField()
{
    return field;
}
